package com.cskaoyan.service;

import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.MarketFeedbackExample;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yi
 * @date 2022/10/13 19:52
 */
@Service
public class AdminFeedbackServiceImpl implements AdminFeedbackService {
    @Autowired
    MarketFeedbackMapper marketFeedbackMapper;
    @Override
    public CommonData<MarketFeedback> queryFeedback(String username, Integer id, BasePageInfo basePageInfo) {
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        marketFeedbackExample.setOrderByClause(basePageInfo.getSort());
        MarketFeedbackExample.Criteria criteria = marketFeedbackExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (username != null && !"".equals(username)) {
            criteria.andUsernameLike("%" + username +"%");
        }
        if (id != null) {
            criteria.andIdEqualTo(id);
        }

        List<MarketFeedback> marketFeedbacks = marketFeedbackMapper.selectByExample(marketFeedbackExample);
        PageInfo<MarketFeedback> marketFeedbackPageInfo = new PageInfo<>(marketFeedbacks);
        return CommonData.data(marketFeedbackPageInfo);
    }
}
